<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>自定义工具栏</title>
  <script src="./js/jexcel.js"></script>
  <script src="./js/jsuites.js"></script>
  <link rel="stylesheet" href="./css/jsuites.css" type="text/css" />
  <link rel="stylesheet" href="./css/jexcel.css" type="text/css" />

  <link rel="stylesheet" type="text/css" href="./css/fonts.icon.css" />
</head>

<body>
  <h1>自定义工具栏</h1>

  <div id="spreadsheet"></div>

  <h3>指令</h3>
  <p>工具栏可以通过一些参数进行定制。</p>
  <ul>
    <li>type: 可以是i(图标)，select(选择下拉菜单)，color(颜色)或colorpicker(颜色选择器)。</li>
    <li>content: 当你使用type:i时定义图标(来自材质图标);<a href="https://material.io/tools/icons/" target="_blank">点击这里查看所有可能的关键字</a></li>
    <li>k：表示样式应应用于单元格;</li>
    <li>v：表示样式的值应应用于单元格;当type:select时，可以定义一个可能值的数组;</li>
    <li>onclick：可以与type:i一起使用，以实现任何自定义方法。默认情况下，该方法将接收Jspreadsheet实例和所有标记的单元格。</li>
  </ul>
</body>

<script type="module">
  import { text } from "./js/language.js";

  let data = [
    ['Canada', 'Cheese', 1],
    ['Japan', 'Apples', 0],
    ['United States', 'Carrots', 1],
    ['China', 'Oranges', 0],
  ];

  let table = jspreadsheet(document.getElementById('spreadsheet'), {
    data: data,
    columns: [
      {
        title: 'Country',
        type: 'autocomplete',
        source: ['Brazil', 'Canada', 'China', 'Japan', 'United States', 'United Kingdom'],
        width: '300px',
      },
      {
        title: 'Food',
        type: 'dropdown',
        source: ['Apples', 'Bananas', 'Carrots', 'Oranges', 'Cheese'],
        width: '150px',
      },
      {
        title: 'Stock',
        type: 'checkbox',
        width: '100px',
      },
    ],
    toolbar: [
      {
        type: 'i',
        content: 'undo',
        onclick: function () {
          table.undo();
        }
      },
      {
        type: 'i',
        content: 'redo',
        onclick: function () {
          table.redo();
        }
      },
      {
        type: 'i',
        content: 'save',
        onclick: function () {
          table.download();
        }
      },
      {
        type: 'select',
        k: 'font-family',
        v: ['Arial', 'Verdana']
      },
      {
        type: 'select',
        k: 'font-size',
        v: ['9px', '10px', '11px', '12px', '13px', '14px', '15px', '16px', '17px', '18px', '19px', '20px']
      },
      {
        type: 'i',
        content: 'format_align_left',
        k: 'text-align',
        v: 'left'
      },
      {
        type: 'i',
        content: 'format_align_center',
        k: 'text-align',
        v: 'center'
      },
      {
        type: 'i',
        content: 'format_align_right',
        k: 'text-align',
        v: 'right'
      },
      {
        type: 'i',
        content: 'format_bold',
        k: 'font-weight',
        v: 'bold'
      },
      {
        type: 'color',
        content: 'format_color_text',
        k: 'color'
      },
      {
        type: 'color',
        content: 'format_color_fill',
        k: 'background-color'
      },
    ],
    text
  });
</script>

</html>